package org.dxw.controller;

import org.dxw.DO.UserDO;
import org.dxw.common.excel.ExportUtil;
import org.dxw.req.UserPageReq;
import org.dxw.resp.PageResponse;
import org.dxw.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    private static final String EXPORT_FINE_NAME = "用户信息";

    @GetMapping("/page")
    public PageResponse<UserDO> page(@ModelAttribute UserPageReq userPageReq){
        return userService.page(userPageReq);
    }

    @GetMapping("/export")
    public void export (@ModelAttribute UserPageReq userPageReq, HttpServletResponse response){
        ExportUtil.handlerExportExcel(response, EXPORT_FINE_NAME, ()->{
            userService.export(userPageReq, response);
        });
    }

    @GetMapping("/test")
    public void test (@ModelAttribute UserPageReq userPageReq, HttpServletResponse response){
        userService.test(userPageReq, response);
    }





}
